<?php

namespace App\Controller\Api;

use App\Controller\AbstractController;
use App\Support\Response;
use Hyperf\Di\Annotation\Inject;
use Qbhy\HyperfAuth\AuthGuard;
use Qbhy\HyperfAuth\AuthManager;

class BaseController extends AbstractController
{
    /**
     * @Inject()
     * @var Response
     */
    protected $response;


    /**
     * 获取当前登录用户ID
     *
     * @return int
     */
    public function uid(): int
    {
        $guard = $this->guard();


        return $guard->check() ? $guard->user()->getId() : 0;
    }


    /**
     *
     * @return array|null
     */
    public function user()
    {
        $guard = $this->guard();

        return $guard->check() ? $guard->user()->toArray() : [];
    }


    /**
     * 获取验证守卫
     *
     * @return mixed|AuthGuard|AuthManager
     */
    public function guard()
    {
        return auth('jwt');
    }

}
